//
//  DmDocument.h
//  FoxitApp
//
//  Created by sijia_liu on 15/4/27.
//
//

#import <Foundation/Foundation.h>
#if 0
#import <MSRightsManagement/MSAuthenticationCallback.h>
#import <MSRightsManagement/MSConsentCallback.h>
#import <MSRightsManagement/MSProtectedData.h>
#import <MSRightsManagementUI/MSEmailInputDelegate.h>
#import <MSRightsManagementUI/MSEmailInputViewController.h>
#import <ADALiOS/ADAuthenticationSettings.h>
#import <ADALiOS/ADAuthenticationContext.h>
#import <MSRightsManagementUI/MSResourcesUtils.h>
#endif
#import "DmUndo.h"
#import "FSPDFObjC.h"

@protocol ISecurityHandler;
@class DmPage;
@class DmTextPage;
@protocol FSPDFUIExtensionsManager;

@interface DocumentInfo : NSObject

@property (nonatomic, retain) NSString *filePath;
@property (nonatomic, retain) NSString *docID;
@property (nonatomic, retain) NSString *author;
@property (nonatomic, retain) NSString *subject;
@property (nonatomic, retain) NSDate *createTime;
@property (nonatomic, retain) NSDate *modTime;
@property (nonatomic, assign) unsigned long long fileSize;

@end

//@class DmAnnot;
@class DmUndo;

@interface DmDocument : NSObject

@property (nonatomic, retain) id<FSPDFUIExtensionsManager> extensionsManager;
//@property (nonatomic,retain) FSPDFDoc *fspdfdoc;
//@property (nonatomic,assign) int isOpened;
//@property (nonatomic,assign) int pageCount;
//@property (nonatomic,retain) DocumentInfo *documentInfo;
@property (nonatomic,copy)   NSString *displayFileName;
//@property (nonatomic,retain) DmFileDescriptor *fileDescriptor;
@property (nonatomic,retain) id<ISecurityHandler> currentSecurityHandler;
@property (nonatomic,retain) NSMutableArray *arrayPageSize;
@property (nonatomic,retain) NSMutableArray *arrayPageCropSize;
@property (nonatomic,retain) NSMutableArray *arrayPageCropInsets;
@property (nonatomic,assign) CropMode cropMode;
@property (nonatomic,assign) UIEdgeInsets cropInsets;
@property (nonatomic,copy)   NSString *jsDataXML;
@property (nonatomic,copy)   NSString *reviewFileName;
@property (nonatomic,copy)   NSString *reviewID;
//@property (nonatomic,retain) NSArray *arrayBookmark;
@property (nonatomic,assign) BOOL isPasswordEncrypted;
@property (nonatomic,assign) BOOL needScaleIcon;
@property (nonatomic,copy) NSString *browseFilePath;
@property (nonatomic,retain) FSPDFDoc *fspdfdoc;
@property (nonatomic,retain) DocumentInfo* documentInfo;
@property (nonatomic,assign) int pageCount;
@property (nonatomic,retain) DmFileDescriptor* fileDescriptor;
@property (nonatomic,assign) int isOpened;

@property (nonatomic,retain) FSAnnot *currentAnnot;


- (int)openDocument:(DmFileDescriptor*)descriptor completion:(void(^)(enum FS_ERRORCODE error))completion;
- (int)closeDocment:(DmFileDescriptor*)descriptor CleanUp:(void (^)())cleanup;
- (int)saveDocument:(DmFileDescriptor*)descriptor needReload:(BOOL)needReload;
- (int)saveDocumentAs:(NSString*)path;
- (int)reloadDocument:(NSString*)filePath;
- (int)reloadDocument;
- (int)encryptDocument:(int)encryptType needReload:(BOOL)needReload;
- (int)removeEncrypt:(int)encryptType;

- (BOOL)setModified:(BOOL)flag;
- (BOOL)getModified;

//- (id<IAnnot>)getCurrentAnnot;
//- (void)setCurrentAnnot:(id<IAnnot> )currentAnnot;

- (FSAnnot*)getCurrentAnnot;
- (void)setCurrentAnnot:(FSAnnot*)currentAnnot;

- (DmPage*)getPage:(int)index;

- (NSRange)deletePage:(NSArray*)indexArray;
- (NSRange)setPageIndex:(NSArray*)indexArray afterIndex:(int)afterIndex;

- (CGSize)getPageSize:(int)index;
- (CGSize)getPageCroppedSize:(int)index;
- (void)calculateAllPageSize;
- (void)calculateAllPageContentSize:(int)margin;
- (int)getTotalHeight:(int)width;

//permission
- (BOOL)canPrint;
- (BOOL)canFillForm;
- (BOOL)canAddAnnot;
- (BOOL)canAssemble;
- (BOOL)canModifyContents;
- (BOOL)canCopyForAssess;
- (BOOL)canCopy;
- (BOOL)canSigning;
- (BOOL)isOwner;
- (int)getSecurityType;
- (BOOL)canUpgradeToOwner;
- (void)upgradeToOwner:(void (^)(BOOL success))callback;
- (BOOL)isReviewDoc;

- (FSPDFPage*)getPDFPage:(int)index;
- (FSPDFTextSelect*)getTextPage:(int)index;

////outline
//- (NSArray*)getOutline:(FSBookmark*)bookmark;
//
////bookmark
//- (NSArray*)getBookmark:(FSBookmark*)bookmark;
//- (FSBookmark*)addBookmark:(NSString*)title index:(int)index bookmark:(FSBookmark*)bookmark;
//- (FSBookmark*)addBookmarkByIndex:(NSString*)title index:(int)index bookmarkIndex:(int)bookmarkIndex;
//- (BOOL)hasBookmark:(int)index;
//- (BOOL)updateBookmark:(NSString*)title bookmark:(FSBookmark*)bookmark;
//- (BOOL)updateBookmarkByIndex:(NSString*)title index:(int)index;
//- (BOOL)deleteBookmark:(FSBookmark*)bookmark;
//- (void)deleteBookmarkByIndex:(int)index;
//- (void)releaseNativeBookmarkPtr:(void**)ptr;

- (BOOL)flatten:(NSString*)filePath;

@end

// : DmUndo
@interface DmDocument()

@property (nonatomic, retain) NSMutableArray *undoItems;
@property (nonatomic, retain) NSMutableArray *redoItems;

-(void)addUndoItem:(id<IDmUndoItem>)undoItem;
-(BOOL)canUndo;
-(BOOL)canRedo;
-(void)undo;
-(void)redo;
-(void)clearUndoRedo;

@end
